package com.qo.qsdk.ui.base;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.TextView;

import com.qo.qsdk.ui.QSDKListener;
import com.qo.qsdk.utils.DynamicUtils;
import com.qo.qsdk.utils.Language;

public class LoadingProgressView {

    private View mCircle;
    private TextView mContent;
    private Context mActivity;
    private LayoutInflater mInflater;
    private View mMain;

    public LoadingProgressView(Context mActivity) {
        this.mActivity = mActivity;
        this.mInflater = LayoutInflater.from(mActivity);
        this.mMain = this.mInflater.inflate(DynamicUtils.layout(mActivity, "qsdk_loading_progress"), null);
        init(mMain);
    }

    public View getMain() {
        return this.mMain;
    }

    private void init(View v) {
        mContent = v.findViewById(DynamicUtils.id(mActivity, "tvContent"));
        mCircle = v.findViewById(DynamicUtils.id(mActivity, "ivCircle"));
        mContent.setText(Language.System_Loading.toString());
    }

    public void show() {
        start();
    }

    public void start() {
        mCircle.startAnimation(rotaAnimation());
    }

    public void stop() {
        mCircle.clearAnimation();
    }

    private Animation rotaAnimation() {
        Animation rotateAnimation = new RotateAnimation(0.0f, 355.0f, 1, 0.5f, 1, 0.5f);
        rotateAnimation.setInterpolator(new LinearInterpolator());
        rotateAnimation.setDuration(500);
        rotateAnimation.setRepeatCount(Animation.INFINITE);
        rotateAnimation.setStartOffset(0);
        rotateAnimation.setRepeatMode(Animation.RESTART);
        return rotateAnimation;
    }
}
